<?php

namespace App\Transformers;

use App\Models\PrizeRecord;
use League\Fractal\TransformerAbstract;

class PrizeRecordTransformer extends TransformerAbstract
{
    protected $availableIncludes = ['user', 'prize', 'filiale'];

    public function transform(PrizeRecord $prizeRecord)
    {
        return [
            'id' => $prizeRecord->id,
            'prize_id' => (int) $prizeRecord->prize_id,
            'user_id' => (int) $prizeRecord->user_id,
            'filiale_id' => (int) $prizeRecord->filiale_id,
            'redeem_code' => $prizeRecord->redeem_code,
            'redeemflag' => (bool)$prizeRecord->redeemflag,
            'redeem_at' => $prizeRecord->redeem_at,
            'sendsmsflag' => (bool)$prizeRecord->sendsmsflag,
            'sendsms_at' => $prizeRecord->sendsms_at,
            'remark' => $prizeRecord->remark,
            'created_at' => $prizeRecord->created_at->toDateTimeString(),
            'updated_at' => $prizeRecord->updated_at->toDateTimeString(),
        ];
    }

    public function includeUser(PrizeRecord $prizeRecord)
    {
        return $this->item($prizeRecord->user, new UserTransformer());
    }

    public function includePrize(PrizeRecord $prizeRecord)
    {
        return $this->item($prizeRecord->prize, new PrizeTransformer());
    }

    public function includeFiliale(PrizeRecord $prizeRecord)
    {
        return $this->item($prizeRecord->filiale, new FiliateTransformer());
    }
}